package pl.prv.polanie.client.dto;
// default package

import java.util.Comparator;

import com.google.gwt.user.client.rpc.IsSerializable;


/**
 * PreferenceType entity. @author MyEclipse Persistence Tools
 */

public class CSVPreferenceTypeDTO extends Object implements IsSerializable, ICSVDTO {

	
    private boolean highlighted;

    public static final int SORT_CONST__NAME = 0;
    public static final int SORT_CONST__COLOR = 1;
    public static final int SORT_CONST__ID = 2;
	

    // Fields    
	private long id;
     private String name;
     private String color;

    // Constructors

    /** default constructor */
    public CSVPreferenceTypeDTO() {
    }

    public CSVPreferenceTypeDTO(long id, String name, String color) {
    	this.id = id;
        this.name = name;
        this.color = color;
    }
    

   
    // Property accessors


    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }

    public String getColor() {
        return this.color;
    }
    
    public void setColor(String color) {
        this.color = color;
    }

   
	public String toString() {
		String result = "" +
			"[ " + CSVPreferenceTypeDTO.class + "]" +
			"name: " + name +
			"color: " + color; 
		return result;
	}
	
	public String toLabel() {
		String result = "" +
			name;
		return result;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public boolean isHighlighted() {
		return highlighted;
	}

	public void setHighlighted(boolean highlighted) {
		this.highlighted = highlighted;
	}


	public String getField(int col) {
		if (col == SORT_CONST__ID) {
			return "" + getId();
		} else if (col == SORT_CONST__NAME) {
			return "" + getName();
		} else if (col == SORT_CONST__COLOR) {
			return "" + getColor();
		}
		return "no field";
	}


	@SuppressWarnings("unchecked")
	public static Comparator getComparator(final int colIndex) {
		Comparator cmp = new Comparator() {
			public int compare(Object o1, Object o2) {

//			    final int BEFORE = -1;
			    final int EQUAL = 0;
//			    final int AFTER = 1;
			    
			    CSVPreferenceTypeDTO obj1;
			    CSVPreferenceTypeDTO obj2;
			    if (o1 instanceof CSVPreferenceTypeDTO && o2 instanceof CSVPreferenceTypeDTO) {

					obj1 = (CSVPreferenceTypeDTO) o1;
					obj2 = (CSVPreferenceTypeDTO) o2;
					
					//this optimization is usually worthwhile, and can
					//always be added
					if ( obj1 == obj2 ) return EQUAL;

					//primitive numbers follow this form
					if (colIndex == SORT_CONST__ID) {
						Long l1 = new Long(obj1.getId());
						Long l2 = new Long(obj2.getId());
						return l1.compareTo(l2);
					} else if (colIndex == SORT_CONST__NAME) {
						return obj1.getName().compareTo(obj2.getName());
					} else if (colIndex == SORT_CONST__COLOR) {
						return obj1.getColor().compareTo(obj2.getColor());
					}
					
				};
				return EQUAL;
			}
		};

		return cmp;
	}





}